<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<title>Condition-<%#actionname%>
		-<%#propertyname%></title>
	<STYLE><%#stylesheet%>
	</STYLE>
	<body marginheight="0" marginwidth="0" topmargin="0" onload="init();">
		<form method="post" ID="Form1">
			<TABLE width="100%" height="100%" bgcolor="<%#bgcolor%>" cellspacing="0" cellpadding="0" ID="Table2">
				<tr>
					<td height="40">Build condition<br>
						<table border="0" ID="Table1">
							<tr>
								<td>
									<SELECT id="Select1" name="Select1" language="javascript" onchange="return Select1_onclick();">
										<OPTION value="(" selected>'('</OPTION>
										<OPTION value="Variable">Variable</OPTION>
										<OPTION value="Content">Content</OPTION>
										<OPTION value=""></OPTION>
									</SELECT>
								</td>
								<td>
									<div id="expr1">&nbsp;</div>
								</td>
								<td>
									<SELECT id="Select2" name="Select2">
										<OPTION value=" = " selected>=</OPTION>
										<OPTION value=" > ">&gt;</OPTION>
										<OPTION value=" < ">&lt;</OPTION>
										<OPTION value=" >= ">&gt;=</OPTION>
										<OPTION value=" <= ">&lt;=</OPTION>
										<OPTION value=" <> ">&lt;&gt;</OPTION>
										<OPTION value=" IN ">IN</OPTION>
										<OPTION value=" Contains ">Contains</OPTION>
									</SELECT>
								</td>
								<td>
									<SELECT id="Select3" name="Select3" language="javascript" onchange="return Select3_onclick();">
										<OPTION value="Value" selected>Value</OPTION>
										<OPTION value="Variable">Variable</OPTION>
										<OPTION value="Content">Content</OPTION>
										<OPTION value=""></OPTION>
									</SELECT>
								</td>
								<td>
									<div id="expr2">&nbsp;</div>
								</td>
								<td>
									<SELECT id="Select5" name="Select5">
										<OPTION value="End" selected>End</OPTION>
										<OPTION value=" And ">And</OPTION>
										<OPTION value=" Or ">Or</OPTION>
										<OPTION value=") And ">')' And</OPTION>
										<OPTION value=") Or ">')' Or</OPTION>
									</SELECT>
								</td>
								<td vAlign="center" align="middle" width="200">
									<INPUT id="Button1" class="buttons" type="submit" value="Add" name="Button1" onclick="return Button1_onclick();">
									<INPUT id="undo" class="buttons" type="button" value="Undo" name="undo" language="javascript" onclick="return undo_onclick()">
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<TR>
					<TD height="1" bgcolor="black"><IMG src="?drawimage=spacer.gif" height="1"></TD>
				</TR>
				<TR>
					<TD height="1" bgcolor="white"><IMG src="?drawimage=spacer.gif" height="1"></TD>
				</TR>
				<tr>
					<td height="150">
						<iframe width="100%" frameborder="no" id="expr" SRC="<%#iframeuri%>">
						</iframe>
					</td>
				</tr>
				<TR>
					<TD height="1" bgcolor="black"><IMG src="?drawimage=spacer.gif" height="1"></TD>
				</TR>
				<TR>
					<TD height="1" bgcolor="white"><IMG src="?drawimage=spacer.gif" height="1"></TD>
				</TR>
				<tr>
					<TD align="right" height="30">
						<INPUT id="Button2" class="buttons" type="button" value="Clear" name="Button2" language="javascript" onclick="return Button2_onclick()">
						<INPUT id="button3" class="buttons" type="button" value="Update" name="button3" onclick="return submitform();">
					</TD>
				</tr>
			</TABLE>
		</form>
		<script language="javascript">
		var i=0;
		var oexprstr;
		var sExpression="<%#sExpression%>";
		var sDispExpression="<%#sDispExpression%>";
		var iOpenBrackets=0;

		var undoExpression;
		var undoDispExpression;
		var undoOpenBrackets;


		var valuediv1 = "<input id='valueinput1' type='text'>";

		var variablediv1 = "<SELECT id='valueinput1'>";
		variablediv1 += "<%#assignvariables1%>";
		variablediv1 +=	"</SELECT>";

		var contentdiv1 = "<SELECT id='valueinput1'>";
		contentdiv1 += "<%#assigncontent1%>";
		contentdiv1 +=	"</SELECT>";

		var valuediv2 = "<input id='valueinput2' type='text'>";

		var variablediv2 = "<SELECT id='valueinput2'>";
		variablediv2 += "<%#assignvariables2%>";
		variablediv2 +=	"</SELECT>";

		var contentdiv2 = "<SELECT id='valueinput2'>";
		contentdiv2 += "<%#assigncontent2%>";
		contentdiv2 +=	"</SELECT>";


		var oexpr2;

		oexpr2 = document.getElementsByTagName("div")["expr2"];

		var oexpr1;

		oexpr1 = document.getElementsByTagName("div")["expr1"];


		function changeDiv( divvar )
		{
			if( !oexpr2 )
				oexpr2 = document.getElementsByTagName("div")["expr2"];


			oexpr2.innerHTML = eval(divvar);
		}

		function changeDiv1( divvar )
		{
			if( !oexpr1 )
				oexpr1 = document.getElementsByTagName("div")["expr1"];


			oexpr1.innerHTML = eval(divvar);
		}

		function Select3_onclick()
		{
			var oselect3 = document.getElementsByTagName("select")["Select3"];

			switch(oselect3.value)
			{
				case "Value": changeDiv("valuediv2");
							break;
				case "Variable": changeDiv("variablediv2");
								break;

				case "Content": changeDiv("contentdiv2");
								break;
			}

			return false;
		}

		function Select1_onclick()
		{
			var oselect1 = document.getElementsByTagName("select")["Select1"];

			switch(oselect1.value)
			{
				case "(":
								//changeDiv1("variablediv1");
								document.getElementsByTagName("select")["Select2"].disabled=true;
								document.getElementsByTagName("select")["Select3"].disabled=true;
								document.getElementsByTagName("select")["Select5"].disabled=true;
								if(document.getElementsByTagName("*")["valueinput1"]!=null)
								document.getElementsByTagName("*")["valueinput1"].disabled=true;
								if(document.getElementsByTagName("*")["valueinput2"]!=null)
								document.getElementsByTagName("*")["valueinput2"].disabled=true;
								break;

				case "Variable": changeDiv1("variablediv1");
								document.getElementsByTagName("select")["Select2"].disabled=false;
								document.getElementsByTagName("select")["Select3"].disabled=false;
								document.getElementsByTagName("select")["Select5"].disabled=false;
								if(document.getElementsByTagName("*")["valueinput1"]!=null)
								document.getElementsByTagName("*")["valueinput1"].disabled=false;
								if(document.getElementsByTagName("*")["valueinput2"]!=null)
								document.getElementsByTagName("*")["valueinput2"].disabled=false;
								break;

				case "Content": changeDiv1("contentdiv1");
								document.getElementsByTagName("select")["Select2"].disabled=false;
								document.getElementsByTagName("select")["Select3"].disabled=false;
								document.getElementsByTagName("select")["Select5"].disabled=false;
								if(document.getElementsByTagName("*")["valueinput1"]!=null)
								document.getElementsByTagName("*")["valueinput1"].disabled=false;
								if(document.getElementsByTagName("*")["valueinput2"]!=null)
								document.getElementsByTagName("*")["valueinput2"].disabled=false;
								break;
			}

			return false;
		}

		function init()
		{
			Select3_onclick();
			Select1_onclick();
			document.getElementsByTagName("input")["undo"].disabled=true;
			document.getElementsByTagName("input")["button3"].disabled=true; //Submit button initially disabled
			if( sExpression != "" )
				document.getElementsByTagName("input")["Button1"].disabled=true; //Disable Add button
			else
				document.getElementsByTagName("input")["Button1"].disabled=false; //Enable Add button

			show_expression(sDispExpression);
		}



		function get_framediv()
		{
			var framedoc;

			var frameobj;

			if(navigator.userAgent.indexOf("Netscape") >0 )
			{
				document.all = document.getElementsByTagName("iframe");
				frameobj = document.all["expr"];
				framedoc = frameobj.contentDocument.getElementsByTagName("*");
				oexprstr = framedoc["exprstr"];
			}
			else
			{
				frameobj = document.frames["expr"];
				oexprstr = frameobj.document.all["exprstr"];
			}

		}

		function show_expression(expression)
		{
			if( !oexprstr )
				get_framediv();
			oexprstr.innerHTML = expression;
		}

		function set_undovalues()
		{
			undoExpression = sExpression;
			undoDispExpression = sDispExpression;
			undoOpenBrackets = iOpenBrackets;
			document.getElementsByTagName("input")["undo"].disabled=false;
		}

		function Button1_onclick()
		{
			var retval=false;

			var oselect1 = document.getElementsByTagName("select")["Select1"];
			var select1values = oselect1.value.split(",");
			if( select1values[0] == "(" )
			{
				set_undovalues();
				if(sExpression.length==0)	{
					sExpression += "(";
					sDispExpression += "(";
				}else{
					sExpression += " (";
					sDispExpression += " (";
				}
				iOpenBrackets++;
			}
			else
			{
				var oselect2 = document.getElementsByTagName("select")["Select2"];
				var oselect3 = document.getElementsByTagName("select")["Select3"];
				var oselect5 = document.getElementsByTagName("select")["Select5"];
				var o1 = document.getElementsByTagName("*")["valueinput1"];
				var o2 = document.getElementsByTagName("*")["valueinput2"];
				var endcond=false;

				if( oselect5.value.substring(0,1) == ")" ) //Incase no open brackets pending dont allow to close the bracket
					if( iOpenBrackets <= 0 )
						return retval;
					else
						iOpenBrackets--;


				if( oselect5.value == "End" )
					endcond=true;

				set_undovalues();

				sExpression += "["; sDispExpression += "[";
				if((o1.value.split(","))[1]==null)	{
					sExpression += (o1.value.split(","))[0];
				}else	{
					sExpression += (o1.value.split(","))[1];
				}
				sDispExpression += (o1.value.split(","))[0];
				sExpression += "]"; sDispExpression += "]";

				if(oselect2.value==" = ")	{
					sExpression += oselect2.value.replace("=","==");/*sDispExpression += oselect2.value;*/
				}
				else	{
					sExpression += oselect2.value.replace("<>","!=");
				}
				sDispExpression += oselect2.value;
				sExpression += "["; sDispExpression += "[";

				if( oselect3.value != "Value" )
				{
					sExpression += ((o2.value.split(","))[1]);
					sDispExpression += ((o2.value.split(","))[0]);
				}
				else
				{
					sExpression += '"'+o2.value+'"';
					sDispExpression += '"'+o2.value+'"';
				}
				sExpression += "]"; sDispExpression += "]";

				if( !endcond )
				{
					sExpression += " "+oselect5.value.replace("And","&&").replace("Or","||");
					sDispExpression += " "+oselect5.value;
				}
				else
				{
					while( iOpenBrackets > 0)
					{
						sExpression += " )"; sDispExpression += " )";
						iOpenBrackets--;
					}
					document.getElementsByTagName("input")["button3"].disabled=false; //Enable submitt button
					document.getElementsByTagName("input")["Button1"].disabled=true; //Disable Add button
				}
			}

			show_expression(sDispExpression);
			return retval;
		}

		function Button2_onclick()
		{
			sExpression="";
			sDispExpression="";
			iOpenBrackets=0;
			document.getElementsByTagName("input")["button3"].disabled=true; //Submit button initially disabled
			document.getElementsByTagName("input")["Button1"].disabled=false; //Enable Add button
			show_expression(sDispExpression);
		}

		function undo_onclick()
		{
			sExpression = undoExpression;
			sDispExpression = undoDispExpression;
			iOpenBrackets = undoOpenBrackets;
			document.getElementsByTagName("input")["undo"].disabled=true; //Disable undo button
			document.getElementsByTagName("input")["button3"].disabled=true; //Disable Submit button
			document.getElementsByTagName("input")["Button1"].disabled=false; //Enable Add button
			show_expression(sDispExpression);
		}

		function ConvertToString(  number,  width )
		{
			var str="";
			var i;

			str=number.toString();
			var l = str.length;
			for(i=0;i<(width-l);i++)
			{
				str = "0" + str;
			}
			return str.substring(0,width);
		}

		function submitform()
		{
			var submitvalue="";

			submitvalue = ConvertToString( sExpression.length, 4 ) + sExpression + ConvertToString( sDispExpression.length, 4) + sDispExpression;
			window.opener.properties("_hidtempstore",submitvalue);
			window.opener.submitform("?mode=edit&<%#qspropertypagename%>=<%#propertypage%>&<%#qspropertyname%>=<%#propertyname%>&<%#SelectedItemQueryString%>");
			window.close();
		}


		</script>
	</body>
</html>
